package com.niji.littly_donkey_android.adapter;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.niji.littly_donkey_android.R;
import com.niji.littly_donkey_android.bean.Message;
import com.niji.littly_donkey_android.util.NetworkGlideImageLoader;
import com.niji.littly_donkey_android.util.UrlUtil;
import com.niji.littly_donkey_android.view.CircleImageView;
import com.xuexiang.xui.adapter.recyclerview.RecyclerViewHolder;

import java.util.List;

/**
 * 清单列表adapter
 * <p>
 */

public class MessageCenterAdapter extends BaseMessageCenterViewAdapter<Message> {

    private OnDeleteClickLister mDeleteClickListener;

    private Context context;

    public MessageCenterAdapter(Context context, List<Message> data) {
        super(context, data, R.layout.item_message_centor);
        this.context = context;
    }

    @Override
    protected void onBindData(RecyclerViewHolder holder, Message bean, int position) {
        View view = holder.getView(R.id.message_center_delete);
        view.setTag(position);
        if (!view.hasOnClickListeners()) {
            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (mDeleteClickListener != null) {
                        mDeleteClickListener.onDeleteClick(v, (Integer) v.getTag());
                    }
                }
            });
        }
        ((TextView) holder.getView(R.id.message_center_title)).setText(bean.getTitle());
        ((TextView) holder.getView(R.id.message_center_id)).setText("" + bean.getId());

        ((TextView) holder.getView(R.id.message_center_message)).setText(bean.getMessage());
        ((TextView) holder.getView(R.id.message_center_time)).setText(bean.getTime());
        ((TextView) holder.getView(R.id.message_center_time)).setTextColor(Color.parseColor("#999999"));
        ((TextView) holder.getView(R.id.message_center_message)).setTextColor(Color.parseColor("#666666"));
        ((TextView) holder.getView(R.id.message_center_title)).setTextColor(Color.parseColor("#333333"));
        CircleImageView message_center_head = (CircleImageView) holder.getView(R.id.message_center_head);
        if (bean.getHead() != null){
            if(!bean.getHead().equals("")){
                NetworkGlideImageLoader.getInstance().displayImage((Activity) context, UrlUtil.URL + bean.getHead(),message_center_head,0,0);
            }
        }
    }

    public void setOnDeleteClickListener(OnDeleteClickLister listener) {
        this.mDeleteClickListener = listener;
    }

    public interface OnDeleteClickLister {
        void onDeleteClick(View view, int position);
    }
}
